/**
 * 
 */
package com.icss.ah.applyHomeDisplay.action;

import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.icss.ah.applyHomeDisplay.service.ApplyHomeDisplayService;
import com.icss.ah.base.action.BaseAction;
import com.icss.ah.base.util.Escape;
import com.icss.ah.login.bean.UserInfoBean;

/**
 * 申请首页展示控制类
 * 1、列表展示
 * 2、新增、编辑、详情展示
 * 3、申请信息保存
 * @date 2017-8-25
 */
@Controller
@Scope("prototype")
public class ApplyHomeDisplayAction extends BaseAction {

	private static final long serialVersionUID = 123423412347798L;
	
	@Autowired
	private ApplyHomeDisplayService applyHomeDisplayService;
	
	private String uuid;
	private String begDate;
	private String endDate;
	private String applyName;
	private String type;
	
	/**
	 * 列表展示页
	 */
	public String toApplyHomeDisplayListPage(){
		if(null != applyName && !"".equals(applyName))
			applyName = Escape.unescape(Escape.unescape(applyName));
		request = getRequest();
		request.setAttribute("begDate", begDate);
		request.setAttribute("endDate", endDate);
		request.setAttribute("applyName", applyName);
		return "toApplyHomeDisplayListPage";
	}
	
	/**
	 * 列表查询
	 */
	public void queryApplyHomeDisplayList(){
		Map<String, String> map = new HashMap<String, String>();
		map.put("begDate", begDate);
		map.put("endDate", endDate);
		map.put("applyName", applyName);
		map.put("startIndex", getStartIndexMysql());
		map.put("rowNums", getEndIndexMysql());
		dataGridJson = applyHomeDisplayService.queryApplyHomeDisplayList(map);
		str2Resp(JSONObject.fromObject(dataGridJson).toString());
	}
	
	/**
	 * 新增、编辑、详情页
	 */
	public String toApplyHomeDisplayPage(){
		UserInfoBean userInfo=getUserInfo("");
		String shopId = userInfo.getShopId();
		Map<String, Object> bean = applyHomeDisplayService.getApplyHomeDisplayInfo(uuid);
		request = getRequest();
		request.setAttribute("begDate", begDate);
		request.setAttribute("endDate", endDate);
		request.setAttribute("applyName", applyName);
		request.setAttribute("type", type);
		request.setAttribute("shopId", shopId);
		request.setAttribute("bean", bean);
		String result = "applyHomeDisplayPage";
		if("info".equals(type)) result = "applyHomeDisplayInfoPage";
		return result;
	}
	
	private String content;
	private String picUrl;
	private String applyTime;
	
	/**
	 * 申请信息保存
	 */
	public void save(){
		UserInfoBean userInfo=getUserInfo("");
		String corpId = userInfo.getCorpId();
		String shopId = userInfo.getShopId();
		Map<String, String> map = new HashMap<String, String>();
		map.put("type", type);
		map.put("uuid", uuid);
		map.put("corpId", corpId);
		map.put("shopId", shopId);
		map.put("applyName", applyName);
		map.put("content", content);
		map.put("picUrl", picUrl);
		map.put("begDate", begDate);
		map.put("endDate", endDate);
		map.put("applyTime", applyTime);
		map.put("status", "0");
		String result = applyHomeDisplayService.save(map);
		str2Resp(result);
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getBegDate() {
		return begDate;
	}

	public void setBegDate(String begDate) {
		this.begDate = begDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getApplyName() {
		return applyName;
	}

	public void setApplyName(String applyName) {
		this.applyName = applyName;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getPicUrl() {
		return picUrl;
	}

	public void setPicUrl(String picUrl) {
		this.picUrl = picUrl;
	}

	public String getApplyTime() {
		return applyTime;
	}

	public void setApplyTime(String applyTime) {
		this.applyTime = applyTime;
	}

}
